package com.iptv.grape.bu.imp;

import android.content.Context;
import android.view.KeyEvent;

import com.iptv.grape.bu.AppState;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.bu.IKeyEventPorc;
import com.iptv.grape.BaseActivity;
import com.iptv.grape.event.EventArgs;
import com.iptv.grape.event.msg.BackVodFullScreenMsg;
import com.iptv.grape.util.WebViewUtils;
import com.iptv.grape.video.XMediaPlayer;

import org.greenrobot.eventbus.EventBus;
// 退出直播全屏播放状态
//@AppState(isShowLiveMenu = false, keyVals = {4})
@AppState(isShowLiveMenu = false, keyVals = {4},curPlayType = "Test")
public class QuitFullScreen implements IKeyEventPorc {
    @Override
    public void onKeyDownEvent(BaseActivity context, XMediaPlayer mediaPlayer,GrapeContext grapeContext, KeyEvent event) {
        mediaPlayer.quitFullScreen();
        grapeContext.setFullScreen(false);
        grapeContext.setFocus(false);
        WebViewUtils.sentKeyMessageToWebView(new BackVodFullScreenMsg(), context.getBridgeWebView());
        if(GrapeContext.curGrapeContext().isQuitFullScreenStopPlay()){
            mediaPlayer.stop();
            mediaPlayer.hiddView();
        }
    }

    public static void quitFullScreen(BaseActivity context){

        if(GrapeContext.curGrapeContext().isShowRecommendUI()){
            context.getBridgeWebView().requestFocus();
            GrapeContext.curGrapeContext().hideRecommendFragment(context);
        }
        if(GrapeContext.curGrapeContext().isShowVodMenu()) {
            context.getBridgeWebView().requestFocus();
            GrapeContext.curGrapeContext().hideVodFragment(context);
        }
        GrapeContext.curGrapeContext().getCurActivity().visibles();
        XMediaPlayer mediaPlayer = GrapeContext.curGrapeContext().getCurMediaPlayer();
        mediaPlayer.quitFullScreen();
        GrapeContext.curGrapeContext().setFullScreen(false);
        GrapeContext.curGrapeContext().setFocus(false);
        WebViewUtils.sentKeyMessageToWebView(new BackVodFullScreenMsg(), context.getBridgeWebView());
        if(GrapeContext.curGrapeContext().isQuitFullScreenStopPlay()){
            mediaPlayer.stop();
            mediaPlayer.hiddView();
        }
        //context.getBridgeWebView().requestFocus();
    }
}
